#include "StdAfx.h"
#include "cPlayerAirplane.h"
	
cPlayerAirplane::cPlayerAirplane( void )
{
	mPosition		= D3DXVECTOR3(0.f, 130.f, -50.f);
	mScale			= D3DXVECTOR3(0.03f, 0.03f, 0.03f);
	mRotation	= D3DXVECTOR3(D3DX_PI, 0.f, D3DX_PI);
	DelayCount	= 0;
	bHitDelay		= 0;
	isLive				= false;
}
//------------------------------------------------------------------------------------------------------------------------
cPlayerAirplane::~cPlayerAirplane(void)
{
}
//------------------------------------------------------------------------------------------------------------------------
void cPlayerAirplane::Create()
{
	cModelMgr& mgr = cModelMgr::getInstance();
	if (isLive == false)
	{
		setModel(mgr.getAniModel( "Player" ));
		isLive = true; 
	}
}
//------------------------------------------------------------------------------------------------------------------------
void cPlayerAirplane::ProcessKeyInput()
{
	animate();
	//world = mOrigin * getWorldTM();
	bPress = false;
	
	if (gDInput->keyDown(DIK_UPARROW))
	{
		D3DXVECTOR3 up( 0.f, 0.f, 0.2f );
		mPosition += up;
	}

	if (gDInput->keyDown(DIK_DOWNARROW))
	{
		D3DXVECTOR3 up( 0.f, 0.f, 0.2f );
		if ( mPosition.z > PLAYER_Z - 10.f )
		{
			mPosition -= up;
		}

		if ( mPosition.y<0.f )
		{
			mPosition += up;
		}
	}

	if (gDInput->keyDown(DIK_RIGHTARROW))
	{
		bPress = true;
	
		D3DXVECTOR3 right(0.2f, 0.f, 0.f);
		mPosition += right;

			if (mRotation.z<D3DX_PI+D3DX_PI*30/180)
			{
				mRotation.z += 0.008f;

				if (gDInput->keyDown(DIK_LEFTARROW) == true)
				{
					mRotation.z = D3DX_PI;
				}
		}
	}

	if (gDInput->keyDown(DIK_LEFTARROW) )
	{
		bPress = true;
		
		D3DXVECTOR3 right(0.2f, 0.f, 0.f);
		mPosition-=right;
		if (mRotation.z>D3DX_PI-D3DX_PI*30/180)
		{
			mRotation.z-=0.008f;
			if (gDInput->keyDown(DIK_RIGHTARROW) == true)
			{
				mRotation.z = D3DX_PI;
			}
		}
	}
		

	if (bPress == false)
	{
		if (mRotation.z>D3DX_PI)
		{
			mRotation.z-=0.01f;
		}
		if (mRotation.z<=D3DX_PI)
		{
			mRotation.z+=0.1f;
		}

		if (mRotation.z<0.f)
		{
			mRotation.z+=0.01f;
		}
		if (mRotation.z>=D3DX_PI)
		{
			mRotation.z-=0.1f;
		}
	}
}
//------------------------------------------------------------------------------------------------------------------------
void cPlayerAirplane::HitDelay()
{
	float fElapsedTime = gGameTime.elapsedTime;

	if( bHitDelay == true )
	{
		static float w_time = 0.f;
		w_time += fElapsedTime;
		DelayCount = w_time/0.05f;
		if( DelayCount >= 30) 
		{
			w_time -= (0.05f * 30);
			DelayCount = w_time/0.05f;
			bHitDelay = false;
		}
	}
}
//------------------------------------------------------------------------------------------------------------------------
